<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>pay</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		
		
		<!--App自定义的css-->
		<!-- <link rel="stylesheet" type="text/css" href="../css/app.css" /> -->
		<style>
			h5 {
				margin: 5px 7px;
			}
			
		</style>
		
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">pay</h1>
		</header>
		<div class="mui-content">
			

						<input type="text" id="txtOrderId" value=""/>


						<button type="button" id="butOrder" class="mui-btn mui-btn-royal" onclick="fnSubmit()">提交</button>

		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/tools.js"></script>
	<script>
	function fnSubmit()
	{
		var channel=null;
		var title = "zdm";
		var strPayType = "";
		var buts = [{title: "支付宝"},{title: "微信"}];
		plus.nativeUI.actionSheet(
		{
			title: "选择支付方式",
			cancel: "取消",
			buttons: buts
		},
		function(sel) 
		{
			//alert(sel.index);
			if(sel.index==0||sel.index==-1)
			{
				return;
			}
			
			switch(buts[sel.index-1].title)
			{
				case "支付宝":					
					strPayType = "alipay";					
				break;
				
				case "微信":					
					strPayType = "weixin";					
				break;
				
			}
			
			mui.plusReady(function()
			{
				plus.payment.getChannels(function(channels){
			        //channel=channels[0];
			        for(var i in channels)
			        {
						channel=channels[i];
						if(channel.id==='alipay' && strPayType == 'alipay')
						{
							break;
						}
						
						if(channel.id==='weixin' && strPayType == 'weixin')
						{
							break;
						}
					}
			    },function(e){
			        alert("获取支付通道失败："+e.message);
			    });
				
				var strPayUrl = "";
				if(strPayType == "alipay")
				{
					strPayUrl = g_SrvUrl+"/zdm/Pay/Alipay/GetPayInfo";
				}
				
				if(strPayType == "weixin")
				{
					strPayUrl = g_SrvUrl+"/zdm/Pay/Wxpay/GetPayInfo";
				}
	alert(strPayUrl);
				plus.nativeUI.showWaiting();
		        mui.post(strPayUrl, {
		            OrderId: document.getElementById("txtOrderId").value
		        }, function(data) {
		            plus.nativeUI.closeWaiting();
		            if (data) 
		            {
		            	//alert(channel);
			            	if(data != "repay")
			            	{
			                plus.payment.request(channel, data, function(result) {
			                    console.log(JSON.stringify(result));
			                    mui.alert(JSON.stringify(result), title);
			                    mui.alert("付费成功", title);
			                }, function(e) {
			                    console.log(JSON.stringify(e));
			                    alert(JSON.stringify(e));
			                    mui.alert("付费失败", title);
			                });
			             }
			            	 else
			            	 {
			            		mui.alert("付费失败,该订单已经支付过", title);
			            	 }
		            } else {
		                plus.nativeUI.alert("支付失败");
		            }
		        });
		    });
		});
		
		
	}    
    </script>  
	
	</body>

</html>